package com.jr.mapper;

import com.jr.pojo.Booking;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface BookingMapper {

    @Insert("INSERT INTO bookings (user_id, provider_id, service_type_id, pet_id, start_date, end_date, " +
            "special_requests, total_price, status, created_at, updated_at) " +
            "VALUES (#{userId}, #{providerId}, #{serviceTypeId}, #{petId}, #{startDate}, #{endDate}, " +
            "#{specialRequests}, #{totalPrice}, #{status}, #{createdAt}, #{updatedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "bookingId")
    int insertBooking(Booking booking);

    @Select("SELECT * FROM bookings WHERE booking_id = #{bookingId}")
    Booking selectById(Integer bookingId);

    @Select("SELECT * FROM bookings WHERE user_id = #{userId}")
    List<Booking> selectByUserId(Integer userId);

    @Select("SELECT * FROM bookings WHERE provider_id = #{providerId}")
    List<Booking> selectByProviderId(Integer providerId);

    @Update("UPDATE bookings SET status = #{status}, updated_at = #{updatedAt} WHERE booking_id = #{bookingId}")
    int updateBookingStatus(Booking booking);
}
